﻿// Created by amoylel on 30/03/2018.
// Copyright (c) 2018 amoylel All rights reserved.

#ifndef AMO_TYPE_TRAITS_9AAE7F9D_49C3_43EE_BBFB_2D1B44666281_HPP__
#define AMO_TYPE_TRAITS_9AAE7F9D_49C3_43EE_BBFB_2D1B44666281_HPP__

#include <string>
#include <cstdint>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <memory>

#include <amo/loop_return_type.hpp>

namespace amo {


    template<typename T> struct is_not_void {
        static const bool value = true;
    };
    template<> struct is_not_void < void > {
        static const bool value = false;
    };
    
    //typedef std::string u8string;	// 以utf8编码的字符串
    typedef std::string astring;	// 以ansi编码的字符串
    // 与平台编码相同的字符串，windows为GB2312 linux为UTF8
    typedef std::string ustring;
    
    
    template<typename T> class is_smart_pointer {
    public:
        const static int32_t value = 0;
        typedef T type;
        typedef std::shared_ptr<T> smart_type;
    };
    
    template<typename T> class remove_smart_pointer {
    public:
        typedef T type;
        typedef std::shared_ptr<T> smart_type;
    };
    
    template<typename T> class is_vector {
    public:
        const static int32_t value = 0;
    };
    
    template<typename T> class is_list {
    public:
        const static int32_t value = 0;
    };
    
    template<typename T> class is_deque {
    public:
        const static int32_t value = 0;
    };
    
    template<typename T> class is_queue {
    public:
        const static int32_t value = 0;
    };
    
    template<typename T> class is_container {
    public:
        const static int32_t value = (is_vector<T>::value | is_list<T >::value |
                                      is_deque< T >::value);
    };
} // namespace amo


#ifndef MAKE_TYPE_TRAITS
#define MAKE_TYPE_TRAITS(_type)\
namespace amo{\
	template<> class is_smart_pointer<std::shared_ptr< _type > > {\
	public:\
		const static int32_t value = 1;\
	};\
	template<> class is_vector<std::vector< _type > > {\
	public:\
		const static int32_t value = 1;\
	};\
	template<> class is_vector<std::vector< std::shared_ptr< _type >  > > {\
	public:\
		const static int32_t value = 1;\
	};\
	template<> class is_list<std::list< _type > > {\
	public:\
		const static int32_t value = 1;\
	};\
	template<> class is_list<std::list< std::shared_ptr< _type >  > > {\
	public:\
		const static int32_t value = 1;\
	};\
	template<> class is_deque<std::deque< _type > > {\
	public:\
		const static int32_t value = 1;\
	};\
	template<> class is_deque<std::deque< std::shared_ptr< _type >  > > {\
	public:\
		const static int32_t value = 1;\
	};\
	template<> class remove_smart_pointer<std::shared_ptr< _type > > {\
	public:\
		typedef _type type;\
		typedef std::shared_ptr< _type > smart_type;\
	};\
}
#endif


MAKE_TYPE_TRAITS(bool)
MAKE_TYPE_TRAITS(char)
MAKE_TYPE_TRAITS(int8_t)
MAKE_TYPE_TRAITS(int16_t)
MAKE_TYPE_TRAITS(int32_t)
MAKE_TYPE_TRAITS(int64_t)
MAKE_TYPE_TRAITS(uint8_t)
MAKE_TYPE_TRAITS(uint16_t)
MAKE_TYPE_TRAITS(uint32_t)
MAKE_TYPE_TRAITS(uint64_t)
MAKE_TYPE_TRAITS(float)
MAKE_TYPE_TRAITS(double)
MAKE_TYPE_TRAITS(std::string)



namespace amo {
    template<typename T>
    class is_json_value {
    public:
        static const int32_t value = 0;
    };
}
#ifndef I_AM_A_JSON_VALUE
#define I_AM_A_JSON_VALUE(_type)\
namespace amo {\
	template<> class is_json_value <_type> {\
	public:\
		static const int32_t value = 1;\
	};\
}
#endif


I_AM_A_JSON_VALUE(bool)
I_AM_A_JSON_VALUE(char)
I_AM_A_JSON_VALUE(int8_t)
I_AM_A_JSON_VALUE(int16_t)
I_AM_A_JSON_VALUE(int32_t)
I_AM_A_JSON_VALUE(int64_t)
I_AM_A_JSON_VALUE(uint8_t)
I_AM_A_JSON_VALUE(uint16_t)
I_AM_A_JSON_VALUE(uint32_t)
I_AM_A_JSON_VALUE(uint64_t)
I_AM_A_JSON_VALUE(float)
I_AM_A_JSON_VALUE(double)
I_AM_A_JSON_VALUE(std::string)


#endif //AMO_TYPE_TRAITS_9AAE7F9D_49C3_43EE_BBFB_2D1B44666281_HPP__

